package com.tengju.motivation.domain.shared;

import lombok.Getter;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

/**
 * @Author: 李大仙
 * @Date: 2021/5/6 1:50 下午
 */
@Getter
public class Month {

    private Integer month;

    private Date startTime;
    private Date endTime;
    private Date nextMonthStartTime;

    private Month() {
    }

    private Month(Integer month) {
        this.month = month;
        startTime = DateUtil.localDateTimeToDate(DateUtil.getMonthMin(month));
        endTime = DateUtil.localDateTimeToDate(DateUtil.getMonthMax(month));
        nextMonthStartTime = DateUtil.localDateTimeToDate(DateUtil.getNextMonthMin(month));
    }

    public static Month of(Integer month) {
        return new Month(month);
    }

    public boolean sameMonth(LocalDateTime localDateTime) {
        long nowTime = DateUtil.localDateTimeToDate(localDateTime).getTime();
        return this.startTime.getTime() <= nowTime && this.endTime.getTime() >= nowTime;
    }

    public boolean sameFirstDay(LocalDateTime localDateTime) {
        return this.startTime.equals(DateUtil.localDateTimeToDate(LocalDateTime.of(localDateTime.toLocalDate(), LocalTime.MIN)));
    }
}
